home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome_100_percent.pak / Unnamed File 000052.txt < prev    next >
Text File  |  2013-04-03  |  2KB  |  61 lines

  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. // Custom bindings for the webstore API.
  6.  
  7. var webstoreNatives = requireNative('webstore');
  8.  
  9. function Installer() {
  10.   this._pendingInstalls = {};
  11. }
  12.  
  13. Installer.prototype.install = function(url, onSuccess, onFailure) {
  14.   var installId = webstoreNatives.Install(url, onSuccess, onFailure);
  15.   if (installId !== undefined) {
  16.     if (installId in this._pendingInstalls)
  17.       throw new Error('Duplicate installId ' + installId);
  18.     this._pendingInstalls[installId] = {
  19.       onSuccess: onSuccess,
  20.       onFailure: onFailure
  21.     };
  22.   }
  23. };
  24.  
  25. Installer.prototype.onInstallResponse = function(installId, success, error) {
  26.   var pendingInstall = this._pendingInstalls[installId];
  27.   if (!pendingInstall) {
  28.     // TODO(kalman): should this be an error?
  29.     return;
  30.   }
  31.  
  32.   try {
  33.     if (success && pendingInstall.onSuccess)
  34.       pendingInstall.onSuccess();
  35.     else if (!success && pendingInstall.onFailure)
  36.       pendingInstall.onFailure(error);
  37.   } finally {
  38.     delete this._pendingInstalls[installId];
  39.   }
  40. };
  41.  
  42. var installer = new Installer();
  43.  
  44. var chromeWebstore = {
  45.   install: function install(url, onSuccess, onFailure) {
  46.     installer.install(url, onSuccess, onFailure);
  47.   }
  48. };
  49.  
  50. // Called by webstore_bindings.cc.
  51. var chromeHiddenWebstore = {
  52.   onInstallResponse: function(installId, success, error) {
  53.     installer.onInstallResponse(installId, success, error);
  54.   }
  55. };
  56.  
  57. // These must match the names in InstallWebstoreBindings in
  58. // chrome/renderer/extensions/dispatcher.cc.
  59. exports.chromeWebstore = chromeWebstore;
  60. exports.chromeHiddenWebstore = chromeHiddenWebstore;
  61.